package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.BO.CollectAddOrDeleteBO;
import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.wx.WxCollectVO;
import com.cskaoyan.service.wx.WxCollectService;
import com.cskaoyan.utils.IdUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;

/**
 * @author WeitenHong
 * @date 2020/10/6 20:20
 */

@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    WxCollectService wxCollectService;

    @RequestMapping("list")
    public BaseRespVo list(Integer type,Integer page,Integer size){
        WxCollectVO wxCollectVO=wxCollectService.list(type,page,size);
        return BaseRespVo.ok(wxCollectVO);
    }

    @RequestMapping("addordelete")
    public BaseRespVo addOrDelete(@RequestBody CollectAddOrDeleteBO collectAddOrDeleteBO){
        if (IdUtils.getId() == 0) {
            BaseRespVo baseRespVo = new BaseRespVo();
            baseRespVo.setErrno(501);
            baseRespVo.setMsg("请登录");
            return baseRespVo;
        }
        String type=wxCollectService.addOrDelete(IdUtils.getId(),collectAddOrDeleteBO.getType(),collectAddOrDeleteBO.getValueId());
        HashMap<String, Object> map = new HashMap<>();
        map.put("type",type);
        return BaseRespVo.ok(map);
    }


}
